import requests
import app
class egoapi:
    def __init__(self):
        self.banner_url = app.BASE_URL + "/api/v1/banner/1"
        self.theme_url=app.BASE_URL + "/api/v1/theme"
        self.recent_goods_url=app.BASE_URL + "/api/v1/product/recent"
        self.token_url=app.BASE_URL + "/api/v1/token/user"
        self.verify_token_url=app.BASE_URL + "/api/v1/token/verify"
        self.address_url=app.BASE_URL + "/api/v1/address"
        self.order_list_url=app.BASE_URL + "/api/v1/order/by_user"
        self.order_create_url=app.BASE_URL + "/api/v1/order"
        self.order_look_url=app.BASE_URL + "/api/v1/order"
        self.category_url = app.BASE_URL + "/api/v1/category/all"
        # 获取商品分类下的某个商品
        self.by_category_url = app.BASE_URL + "/api/v1/product/by_category"
        # 获取商品详情
        self.product_detail_url = app.BASE_URL + "/api/v1/product"

    #轮播图
    def get_banner(self):
        return requests.get(url=self.banner_url)
    #专题栏目
    def get_theme(self,ids):
        return requests.get(url=self.theme_url,params=ids)
    #最近新品
    def get_recent_goods(self):
        return requests.get(url=self.recent_goods_url)
    #获取token
    def get_token(self, headers,code):
        return requests.post(url=self.token_url,headers=app.HEADERS, json={"code": code})
    #验证token
    def  get_verify_code(self,token):
        return requests.post(url=self.verify_token_url,json={"token":token})
    #获取地址信息
    def  get_address(self,token):
        return requests.get(url=self.address_url,headers={"token":token})
    #获取用户订单列表
    def get_order_list(self,page,token):
        return requests.get(url=self.order_list_url,headers={"token":token},params=page)
    #创建订单
    def get_order_create(self,token,jsondata):
        return requests.post(url=self.order_create_url,headers={"token":token},json=jsondata)
    #查看订单
    def get_order_look(self,token,oder_id):
        order_look_url=self.order_look_url + "/" + oder_id
        return requests.get(url=order_look_url,headers={"token":token})
    #获取商品分类
    def get_category(self):
        return requests.get(url=self.category_url)
    #获取商品分类下的某个商品
    def get_by_category(self,id):
        return requests.get(url=self.by_category_url,params={"id":id})

    # 获取商品信息
    def get_product_detail(self, product_id):
        return requests.get(self.product_detail_url + "/" + str(product_id))










'''ego_api=egoapi()
response=ego_api.get_theme("ids=1")
print("专题栏位信息：",response.json())
response=ego_api.get_recent_goods()
print("最近新品：",response.json())
response=ego_api.get_token(headers=app.HEADERS,code=app.CODE)
print("获取的令牌为：",response.json())
response=ego_api.get_verify_code(token=app.TOKEN)
print("验证令牌：",response.json())
response=ego_api.get_address(token=app.TOKEN)
print("获取的地址信息：",response.json())
response=ego_api.get_order_list("page=1",token=app.TOKEN)
print("用户订单列表信息：",response.json())
response=ego_api.get_order_create(token=app.TOKEN,jsondata= {"products": [{"product_id": 8, "count": 1}, {"product_id": 10, "count": 2}]})
print("创建订单：",response.json())
response=ego_api.get_order_look(token=app.TOKEN,oder_id="110")
print("订单信息为：",response.json())
response=ego_api.get_category()
print("商品分类信息为：",response.json())
response=ego_api.get_by_category(2)
print("商品分类下的商品信息为：",response.json())
response=ego_api.get_product_detail(2)
print("商品详细信息为：",response.json())'''